package com.cqjtu.eecs.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cqjtu.eecs.entity.GoalRequirement;
import com.cqjtu.eecs.entity.Requirement;
import com.cqjtu.eecs.entity.TrainingGoal;
import com.cqjtu.eecs.entity.dto.GoalRequirementDTO;
import com.cqjtu.eecs.entity.vo.GoalRequirementVO;
import com.cqjtu.eecs.mapper.GoalRequirementMapper;
import com.cqjtu.eecs.mapper.RequirementMapper;
import com.cqjtu.eecs.mapper.TrainingGoalMapper;
import com.cqjtu.eecs.service.IGoalRequirementService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 培养目标-毕业要求 服务实现类
 * </p>
 *
 * @author    
 * @since 2022-03-07
 */
@Service
public class GoalRequirementServiceImpl extends ServiceImpl<GoalRequirementMapper, GoalRequirement> implements IGoalRequirementService {

    @Autowired
    private GoalRequirementMapper goalRequirementMapper;

    @Autowired
    private RequirementMapper requirementMapper;

    @Autowired
    private TrainingGoalMapper trainingGoalMapper;

    @Override
    public GoalRequirementVO getGoalRequirementByPid(String pid) {
        GoalRequirementVO goalRequirementVO=new GoalRequirementVO();

        int sumGoal=trainingGoalMapper.selectCount(new QueryWrapper<TrainingGoal>().eq("pid",pid));
        goalRequirementVO.setMaxTrainingGoalCode(sumGoal);


        List<GoalRequirementDTO> goalRequirementDTOS=goalRequirementMapper.getGoalRequirement2(pid);
        List<List<Integer>> objects = new ArrayList<List<Integer>>() ;
        for (GoalRequirementDTO i:goalRequirementDTOS
             ) {
            List<Integer> integers=goalRequirementMapper.getGoalRequirement3(i.getPid(),i.getRequirement_code());
            objects.add(integers);
        }


        goalRequirementVO.setData(objects);

        return goalRequirementVO;
    }
}
